const Router = require('koa-router');
const router = new Router();
// 删除角色
const {db, Op, QueryTypes} = require("../models/db");
const tool = require("../tools/tool");
// 科目余额明细
router.post('/card/getKmyemx', async ctx => {
    let formData = ctx.request.body.formData
    let tenantId = ctx.user.tenantId
    let subjectId = formData.subjectId
    let beg = formData.begDate
    let end = formData.endDate
    let field = formData.field
    if(field === 'price1') {
        let sql = `
        select a.billDate,a.billNo,b.price1 price,a.cby,c.name cbyName,a.createdAt,b.remark from card a inner join card_info b on a.id=b.cardId and a.billState='accounted' and a.tenantId=${tenantId} 
        and b.subjectId=${subjectId} and a.billDate between '${beg}' and '${end}' and isnull(price1,0)<>0 
        left join admin c on a.cby=c.id 
    `
        let list = await db.query(sql, {type: QueryTypes.SELECT})
        return ctx.suc('', list)
    }
    if(field === 'price2') {
        let sql = `
        select a.billDate,a.billNo,b.price2 price,a.cby,c.name cbyName,a.createdAt,b.remark from card a inner join card_info b on a.id=b.cardId and a.billState='accounted' and a.tenantId=${tenantId} 
        and b.subjectId=${subjectId} and a.billDate between '${beg}' and '${end}' and isnull(price2,0)<>0 
        left join admin c on a.cby=c.id 
    `
        let list = await db.query(sql, {type: QueryTypes.SELECT})
        return ctx.suc('', list)
    }

})


module.exports = router;